package com.treasure.mall.biz.service.core.user.impl;

import com.treasure.mall.biz.entity.user.IMUSerSigPO;
import com.treasure.mall.biz.entity.user.UserPO;
import com.treasure.mall.biz.remote.live.TencentIMService;
import com.treasure.mall.biz.repository.user.IMUSerSigRepository;
import com.treasure.mall.biz.service.core.user.IMUSerSigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 *
 * +---------------------------------------------------------
 * * @package: com.treasure.mall.biz.service.core.user.impl
 * * @author: guomw (guomwchen@foxmail.com)
 * * @date: 2020/6/29 20:38
 * * @since: V1.0.0
 * +---------------------------------------------------------
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的
 * Copyright 2019-2022 com.treasure.mall.biz.service.core.user.impl Inc. All rights reserved.
 */
@Service
public class IMUSerSigServiceImpl implements IMUSerSigService {

    @Autowired
    private TencentIMService tencentIMService;

    @Autowired
    private IMUSerSigRepository imuSerSigRepository;

    @Override
    public IMUSerSigPO save(UserPO user) {
        IMUSerSigPO imuSerSigPO = new IMUSerSigPO();
        imuSerSigPO.setUserId(user.getUserId());
        imuSerSigPO.setImUserId(user.toIMUserName());
        Map<String, String> userSig = tencentIMService.clientLoginInformation(user, null);
        imuSerSigPO.setUserSig(userSig.get("userSig"));
        return imuSerSigRepository.save(imuSerSigPO);
    }

    @Override
    public IMUSerSigPO findById(Long id) {
        return imuSerSigRepository.findById(id).orElse(null);
    }

}
